/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Client;

import Utility.exceptions.ExceptionCaricamentoProfilo;
import Utility.exceptions.ExceptionCertificatoNonCreato;
import Utility.exceptions.ExceptionFirmaNonCorretta;
import Utility.exceptions.ExceptionGenerazioneChiavi;
import Utility.exceptions.ExceptionGenerazionePKCS10;
import Utility.exceptions.ExceptionSalvataggioFile;
import Utility.exceptions.ExceptionSalvataggioPem;
import Utility.exceptions.ExceptionStatusCertificato;
import Utility.exceptions.ExceptionVerificaFirma;
import com.itextpdf.text.DocumentException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.security.cert.CRLException;
import java.security.cert.CertificateException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.xmlrpc.XmlRpcException;
import org.bouncycastle.ocsp.OCSPException;
import org.xml.sax.SAXException;

/**
 *
 * @author Gonel
 */
public class ClientGui extends javax.swing.JFrame {

    Client client=null;
    /**
     * Creates new form ClientGui
     * @param c: l'oggetto Client corrispondente
     */
    public ClientGui(Client c) {
        client=c;
        initComponents();
        
        if(new File("key/userinfo.xml").exists() && new File("key/pubKeyFirma.pem").exists()){
            // utente gia' creato
            System.out.println("Utente trovato");
            jFrame1.setVisible(true);
            jFrame1.isFocused();
            jFrame1.setAlwaysOnTop(true);            
            jFrame1.setSize(500, 400);
            jFrame2.setVisible(false);
            
            // l'utente è tornato, vedo quali pulsanti disabilitare
            
            // se non esiste il certificato, posso solo creare una richiesta o,
            // nel caso l'abbia gia fatta, ottenere il certificato
                if(new File("cert/my.cert").exists()==false){
                    revocaCertificatoBUtton.setEnabled(false);
                    ottieniCrittografiaButton.setEnabled(false);
                    richiediCrittografiaButton.setEnabled(false);
                    revocaCrittografiaButton.setEnabled(false);
                    rinnovoCertificatoButton.setEnabled(false);
                    rinnovoCertificatoCrittografiaButton.setEnabled(false);
                    
                    firmaPdf.setEnabled(false);
                    controllaFirmaPdfButton.setEnabled(false);
                    crittaPdfButton.setEnabled(false);
                    decrittaPdfButton.setEnabled(false);
                    
                    // se non esiste nemmeno la richiesta, posso solo crearla
                    if(new File("key/pkcs10-Firma.p10").exists()==false){
                        ottieniCertificatoButton.setEnabled(false);
                    }
                }else{
                    // il certificato di firma esiste
                    // se non esiste quello di Crittografia, idem come sopra
                    if(new File("cert/myCrit.cert").exists()==false){
                        revocaCrittografiaButton.setEnabled(false);
                        rinnovoCertificatoCrittografiaButton.setEnabled(false);
                        crittaPdfButton.setEnabled(false);
                        decrittaPdfButton.setEnabled(false);
            
                        // se non c'è nemmeno la richiesta, non posso nemmeno ottenerlo
                        if(new File("key/pkcs10-Crittografia.p10").exists()==false){
                            ottieniCrittografiaButton.setEnabled(false);
                        }
                    }
                }
            
        }else{
            // utente da creare
            System.out.println("Utente da creare");
            jFrame2.setVisible(true);
            jFrame2.isFocused();
            jFrame2.setAlwaysOnTop(true);
            jFrame2.setSize(500, 500);
            jFrame1.setVisible(false);
            // disabilito pulsanti
            ottieniCertificatoButton.setEnabled(false);
            revocaCertificatoBUtton.setEnabled(false);
            ottieniCrittografiaButton.setEnabled(false);
            richiediCrittografiaButton.setEnabled(false);
            revocaCrittografiaButton.setEnabled(false);
            
            rinnovoCertificatoButton.setEnabled(false);
            rinnovoCertificatoCrittografiaButton.setEnabled(false);

            firmaPdf.setEnabled(false);
            controllaFirmaPdfButton.setEnabled(false);
            crittaPdfButton.setEnabled(false);
            decrittaPdfButton.setEnabled(false);
                    
        }

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jFrame2 = new javax.swing.JFrame();
        jLabel7 = new javax.swing.JLabel();
        email = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        country = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        unit = new javax.swing.JTextField();
        nome = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        organization = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        cognome = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        password = new javax.swing.JPasswordField();
        jLabel8 = new javax.swing.JLabel();
        jFrame1 = new javax.swing.JFrame();
        jButton2 = new javax.swing.JButton();
        passwordEsistente = new javax.swing.JPasswordField();
        jLabel9 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        keyBits1 = new javax.swing.JComboBox();
        richiediCertificatoButton = new javax.swing.JButton();
        ottieniCertificatoButton = new javax.swing.JButton();
        richiediCrittografiaButton = new javax.swing.JButton();
        statusLabel = new javax.swing.JLabel();
        revocaCertificatoBUtton = new javax.swing.JButton();
        revocaCrittografiaButton = new javax.swing.JButton();
        ottieniCrittografiaButton = new javax.swing.JButton();
        rinnovoCertificatoButton = new javax.swing.JButton();
        rinnovoCertificatoCrittografiaButton = new javax.swing.JButton();
        controllaFirmaPdfButton = new javax.swing.JButton();
        firmaPdf = new javax.swing.JButton();
        crittaPdfButton = new javax.swing.JButton();
        decrittaPdfButton = new javax.swing.JButton();
        controllaValiditaButton = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator2 = new javax.swing.JSeparator();
        jLabel10 = new javax.swing.JLabel();
        jSeparator3 = new javax.swing.JSeparator();
        jSeparator4 = new javax.swing.JSeparator();

        jFrame2.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        jFrame2.setAlwaysOnTop(true);

        jLabel7.setText("Email");

        jLabel6.setText("Paese");

        jLabel5.setText("Unita'");

        jLabel1.setText("Nome");

        jButton1.setText("OK");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel3.setText("Organizzazione");

        jLabel2.setText("Cognome");

        jLabel4.setText("Password");

        password.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                passwordActionPerformed(evt);
            }
        });

        jLabel8.setText("Inserire i dati dell'utente");

        javax.swing.GroupLayout jFrame2Layout = new javax.swing.GroupLayout(jFrame2.getContentPane());
        jFrame2.getContentPane().setLayout(jFrame2Layout);
        jFrame2Layout.setHorizontalGroup(
            jFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jFrame2Layout.createSequentialGroup()
                .addGap(96, 96, 96)
                .addGroup(jFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jFrame2Layout.createSequentialGroup()
                        .addGroup(jFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(33, 33, 33)
                        .addGroup(jFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(email, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(country, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(unit, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(nome, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(organization, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cognome, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(password, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jFrame2Layout.createSequentialGroup()
                        .addGap(134, 134, 134)
                        .addComponent(jButton1))
                    .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(229, Short.MAX_VALUE))
        );
        jFrame2Layout.setVerticalGroup(
            jFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jFrame2Layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addComponent(jLabel8)
                .addGap(33, 33, 33)
                .addGroup(jFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(nome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(cognome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(organization, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(unit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(country, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(email, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(37, 37, 37)
                .addGroup(jFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(password, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(18, 18, 18)
                .addComponent(jButton1)
                .addContainerGap(75, Short.MAX_VALUE))
        );

        jFrame1.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jButton2.setText("OK");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel9.setText("Inserire la password dell'utente");

        javax.swing.GroupLayout jFrame1Layout = new javax.swing.GroupLayout(jFrame1.getContentPane());
        jFrame1.getContentPane().setLayout(jFrame1Layout);
        jFrame1Layout.setHorizontalGroup(
            jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jFrame1Layout.createSequentialGroup()
                .addGap(86, 86, 86)
                .addGroup(jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jButton2)
                    .addComponent(passwordEsistente, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9))
                .addContainerGap(87, Short.MAX_VALUE))
        );
        jFrame1Layout.setVerticalGroup(
            jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jFrame1Layout.createSequentialGroup()
                .addGap(65, 65, 65)
                .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(passwordEsistente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(63, 63, 63)
                .addComponent(jButton2)
                .addGap(78, 78, 78))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel12.setText("Client");

        jLabel13.setText("Bit chiave");

        keyBits1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1024", "2048", "4096" }));

        richiediCertificatoButton.setText("Richiedi certificato");
        richiediCertificatoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                richiediCertificatoButtonActionPerformed(evt);
            }
        });

        ottieniCertificatoButton.setText("Ottieni certificato");
        ottieniCertificatoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ottieniCertificatoButtonActionPerformed(evt);
            }
        });

        richiediCrittografiaButton.setText("Richiedi certificato di Crittografia");
        richiediCrittografiaButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                richiediCrittografiaButtonActionPerformed(evt);
            }
        });

        statusLabel.setBackground(new java.awt.Color(255, 254, 209));

        revocaCertificatoBUtton.setText("Revoca certificato");
        revocaCertificatoBUtton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                revocaCertificatoBUttonActionPerformed(evt);
            }
        });

        revocaCrittografiaButton.setText("Revoca certificato di Crittografia");
        revocaCrittografiaButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                revocaCrittografiaButtonActionPerformed(evt);
            }
        });

        ottieniCrittografiaButton.setText("Ottieni certificato di Crittografia");
        ottieniCrittografiaButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ottieniCrittografiaButtonActionPerformed(evt);
            }
        });

        rinnovoCertificatoButton.setText("Rinnovo certificato");
        rinnovoCertificatoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rinnovoCertificatoButtonActionPerformed(evt);
            }
        });

        rinnovoCertificatoCrittografiaButton.setText("Rinnovo certificato crittografia");
        rinnovoCertificatoCrittografiaButton.setActionCommand("Rinnovo certificato Crittografia");
        rinnovoCertificatoCrittografiaButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rinnovoCertificatoCrittografiaButtonActionPerformed(evt);
            }
        });

        controllaFirmaPdfButton.setText("Controlla validità pdf");
        controllaFirmaPdfButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                controllaFirmaPdfButtonActionPerformed(evt);
            }
        });

        firmaPdf.setText("Firma Pdf");
        firmaPdf.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                firmaPdfActionPerformed(evt);
            }
        });

        crittaPdfButton.setText("Critta Pdf");
        crittaPdfButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                crittaPdfButtonActionPerformed(evt);
            }
        });

        decrittaPdfButton.setText("Decritta Pdf");
        decrittaPdfButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                decrittaPdfButtonActionPerformed(evt);
            }
        });

        controllaValiditaButton.setText("Controlla validità certificato");
        controllaValiditaButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                controllaValiditaButtonActionPerformed(evt);
            }
        });

        jLabel10.setText("Pdf");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(statusLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jSeparator1)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 760, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(186, 186, 186)
                                        .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(controllaFirmaPdfButton, javax.swing.GroupLayout.DEFAULT_SIZE, 142, Short.MAX_VALUE)
                                            .addComponent(firmaPdf, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                        .addGap(43, 43, 43)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(crittaPdfButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(decrittaPdfButton, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                .addGap(0, 0, Short.MAX_VALUE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(jLabel12))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(31, 31, 31)
                                .addComponent(jLabel13)
                                .addGap(18, 18, 18)
                                .addComponent(keyBits1, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(richiediCertificatoButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(ottieniCertificatoButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(revocaCertificatoBUtton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(rinnovoCertificatoButton, javax.swing.GroupLayout.DEFAULT_SIZE, 145, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(richiediCrittografiaButton, javax.swing.GroupLayout.DEFAULT_SIZE, 198, Short.MAX_VALUE)
                                    .addComponent(ottieniCrittografiaButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(revocaCrittografiaButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(rinnovoCertificatoCrittografiaButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(controllaValiditaButton, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(250, 250, 250))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jLabel12)
                .addGap(46, 46, 46)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel13)
                    .addComponent(keyBits1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(richiediCertificatoButton)
                    .addComponent(richiediCrittografiaButton)
                    .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ottieniCertificatoButton)
                    .addComponent(ottieniCrittografiaButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(revocaCertificatoBUtton)
                    .addComponent(revocaCrittografiaButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(rinnovoCertificatoButton)
                    .addComponent(rinnovoCertificatoCrittografiaButton))
                .addGap(18, 18, 18)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(controllaValiditaButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(crittaPdfButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(decrittaPdfButton))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(firmaPdf)
                            .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(controllaFirmaPdfButton)))
                .addGap(18, 18, 18)
                .addComponent(statusLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        controllaFirmaPdfButton.getAccessibleContext().setAccessibleName("Verifica Pdf");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void passwordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_passwordActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_passwordActionPerformed

    /**
     * Click sul button nel form per la creazione di un nuovo utente
     * @param evt 
     */
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
       if(nome.getText().isEmpty() || cognome.getText().isEmpty() || organization.getText().isEmpty() || unit.getText().isEmpty() || country.getText().isEmpty() || email.getText().isEmpty() || password.getText().isEmpty()){
           System.out.println("Dati mancanti");
           // Dati mancanti
       }else{
            try {
                // Form compilato correttamente. Procedo con la creazione del profilo
               if(client.creaProfilo(nome.getText(), cognome.getText(), organization.getText(), unit.getText(),country.getText(),email.getText(),password.getText()))
               {
                   // client creato
                     System.out.println("Utente creato");
                     jFrame2.setVisible(false);
                    
                     // devo ancora creare le chiavi RSA!!!
                     
               }else{
                   //errore
                   System.out.println("Errore nella creazione dell'utente");
             
               }
               
            } catch (Exception ex) {
                Logger.getLogger(ClientGui.class.getName()).log(Level.SEVERE, null, ex);
            }
           
       }
        
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * Click sul button nel form per l'inserimento della pwd per sbloccare la PrivKey
     * @param evt 
     */
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        // L'utente ha inserito la password per lo sblocco della chiave privata
        
         
        try {
            client.setPassword(passwordEsistente.getText());            
            client.caricaProfilo();
            jFrame1.setVisible(false);
        } catch (Exception ex) {
            this.jLabel9.setText("Errore nella password e caricamento dell'utente");
        }         
    }//GEN-LAST:event_jButton2ActionPerformed

    private void richiediCertificatoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_richiediCertificatoButtonActionPerformed
        this.gestioneRichiesta(Utility.Utility.FIRMA, Integer.parseInt(keyBits1.getSelectedItem().toString()));        
    }//GEN-LAST:event_richiediCertificatoButtonActionPerformed

    /**
     * Chiedo alla Ca lo status del certificato e nel caso sia pronto lo recupero
     * @param evt 
     */
    private void ottieniCertificatoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ottieniCertificatoButtonActionPerformed

        this.gestioneOttieni(Utility.Utility.FIRMA);
    }//GEN-LAST:event_ottieniCertificatoButtonActionPerformed

    /*
     * Richiesta di un certificato per la crittografia
     */
    private void richiediCrittografiaButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_richiediCrittografiaButtonActionPerformed
        this.gestioneRichiesta(Utility.Utility.CRITTOGRAFIA, Integer.parseInt(keyBits1.getSelectedItem().toString()));        
    }//GEN-LAST:event_richiediCrittografiaButtonActionPerformed

    /**
     * Funzione gestione gui richiesta certificato
     * @param tipo
     * @param grandezza 
     */
    private void gestioneRichiesta(int tipo, int grandezza){
        int status;
        try {
            status = client.richiediCertificato(tipo, grandezza);

            switch(status){
                case 0: this.statusLabel.setText("Errore nella richiesta. La richiesta potrebbe essere ancora in coda.");break;
                case 1: this.statusLabel.setText("Richiesta andata a buon fine");
                break;
                case 2: this.statusLabel.setText("E' già presente una richiesta uguale in coda di accettazione");break;
                case 3: this.statusLabel.setText("La validazione della firma della richiesta ha avuto esito negativo");break;                
            }
            
            if(tipo == Utility.Utility.CRITTOGRAFIA){
                this.ottieniCrittografiaButton.setEnabled(true);
            }else{
                this.ottieniCertificatoButton.setEnabled(true);
            }
            
        } catch (XmlRpcException ex) {
            this.statusLabel.setText("Problemi di connessione verso il server: "+Utility.Utility.URL_SERVER); 
        } catch (ExceptionGenerazioneChiavi ex) {
            this.statusLabel.setText("Errore nella generazione delle chiavi"); 
        } catch (ExceptionFirmaNonCorretta ex) {
            this.statusLabel.setText("Firma della risposta non corretta");
        } catch (ExceptionCaricamentoProfilo ex) {
            this.statusLabel.setText("Errore nel caricamento del profilo");
        } catch (ExceptionGenerazionePKCS10 ex) {
            this.statusLabel.setText("Errore nella generazione del pkcs10");
        } catch (ExceptionSalvataggioPem ex) {
            this.statusLabel.setText("Errore nel salvataggio del pem");
        } catch (ExceptionSalvataggioFile ex) {
            this.statusLabel.setText("Errore nel salvataggio del file xml della richiesta");
        } catch (ExceptionVerificaFirma ex) {
            this.statusLabel.setText("Errore nella funzione di verifica della firma");
        }      
    }
    
    /**
     * Revoca il certificato di firma
    * 0 se revoca fallita    
    * 1 se ok
    * 2 se firma non valida
    * 3 errore nella verifica della firma    
    * 4 qualche errore nel database
    * 5 firma risposta non valida 
     * @param evt 
     */
    private void revocaCertificatoBUttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_revocaCertificatoBUttonActionPerformed
        this.gestioneRevocaGui(Utility.Utility.FIRMA);
    }//GEN-LAST:event_revocaCertificatoBUttonActionPerformed

    
    /**
     * Revoca il certificato di crittografia
     * @param evt 
     */
    private void revocaCrittografiaButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_revocaCrittografiaButtonActionPerformed
        this.gestioneRevocaGui(Utility.Utility.CRITTOGRAFIA);
    }//GEN-LAST:event_revocaCrittografiaButtonActionPerformed

    /**
     * Funzione di supporto per gestire la gui nei pulsanti di revoca
     * @param tipo 
     */
    private void gestioneRevocaGui(int tipo){
        try {
            int status = client.revocaCertificato(tipo);
            switch(status){
                case 0: this.statusLabel.setText("Certificato assente o già revocato");break;
                case 1: this.statusLabel.setText("Il certificato è stato revocato con successo");break;
                case 2: this.statusLabel.setText("La firma della richiesta è risultata non valida");break;
                case 3: this.statusLabel.setText("Errore nella verifica della firma nella CA");break;                
                case 4: this.statusLabel.setText("Errore nel database");break;                                    
                case 5: this.statusLabel.setText("Firma della risposta non valida");break;                                                                  
            }            
        } catch (XmlRpcException ex) {
            this.statusLabel.setText("Errore di connessione");
        } catch (ExceptionVerificaFirma ex) {
            this.statusLabel.setText("Errore nella verifica della firma");
        }    
    }
    
    /**
     * Recupero lo stato del certificato di crittografia. Se è pronto allora recupero il certificato
     * @param evt 
     */
    private void ottieniCrittografiaButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ottieniCrittografiaButtonActionPerformed
        this.gestioneOttieni(Utility.Utility.CRITTOGRAFIA);              
    }//GEN-LAST:event_ottieniCrittografiaButtonActionPerformed

    /**
     * Funzione per la gestione della gui in OTTIENI CERTIFICATO
     * @param tipo 
     */
    private void gestioneOttieni(int tipo){
        try {
            try {
                if(client.ottieniCertificato(tipo)){
                    this.statusLabel.setText("Certificato ottenuto");
                    if(tipo == Utility.Utility.CRITTOGRAFIA){
                        revocaCrittografiaButton.setEnabled(true);
                        rinnovoCertificatoCrittografiaButton.setEnabled(true);
                        crittaPdfButton.setEnabled(true);
                        decrittaPdfButton.setEnabled(true);
                    }else{
                        richiediCrittografiaButton.setEnabled(true);
                        revocaCertificatoBUtton.setEnabled(true);
                        rinnovoCertificatoButton.setEnabled(true);
                        firmaPdf.setEnabled(true);
                        controllaFirmaPdfButton.setEnabled(true);
                    }
                }else {
                    this.statusLabel.setText("Il certificato non esiste");
                }
            } catch (XmlRpcException ex) {
                this.statusLabel.setText("Errore di connessione");
            } catch (ExceptionVerificaFirma ex) {
                this.statusLabel.setText("Errore nella funzione di verifica della firma");
            } catch (ExceptionStatusCertificato ex) {
                this.statusLabel.setText("Errore nella richiesta dello status del certificato");
            } catch (ExceptionSalvataggioPem ex) {
                this.statusLabel.setText("Errore nel salvataggio del certificato");
            }
        } catch (ExceptionCertificatoNonCreato ex) {
            this.statusLabel.setText("Errore nella creazione del certificato dal certificato ricevuto dalla CA");      
        } catch (ExceptionFirmaNonCorretta ex) {
            this.statusLabel.setText("Errore nella verifica della firma ricevuta");
        }     
    }
    
    /**
     * Funzione per la gestione gui del rinnovo
     * 0 rinnovo fallito
     * 1 rinnovo con successo
     * 2 firma non valida
     * 
     * @param tipo
     * @param dimensione_chiavi 
     */
    private void gestioneRinnovo(int tipo, int dimensione_chiavi, String nome_chiave){
        try {        
            int status = client.rinnovoCertificato(tipo, dimensione_chiavi, nome_chiave);
            switch(status){
                case 0: this.statusLabel.setText("Certificato non rinnovabile o già rinnovato");break;
                case 1: this.statusLabel.setText("Il certificato è stato rinnovato con successo");break;
                case 2: this.statusLabel.setText("Firma inviata non risultata valida");break;                                                                
            }               
        } catch (ExceptionGenerazioneChiavi ex) {
            this.statusLabel.setText("Errore nella generazione delle chiavi");
        } catch (ParserConfigurationException ex) {
            this.statusLabel.setText("Errore nella creazione del documento da inviare");
        } catch (XmlRpcException ex) {
            this.statusLabel.setText("Problema di connessione");
        } catch (ExceptionVerificaFirma ex) {
            this.statusLabel.setText("Errore nella funzione di verifica firma");
        } catch (ExceptionFirmaNonCorretta ex) {
            this.statusLabel.setText("Firma ricevuta non corretta");
        }
      
    }
    
    /**
     * Rinnovo certificato
     * @param evt 
     */
    private void rinnovoCertificatoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rinnovoCertificatoButtonActionPerformed
        this.gestioneRinnovo(Utility.Utility.FIRMA, Integer.parseInt(keyBits1.getSelectedItem().toString()), Utility.Utility.NOME_FILE_CHIAVE_FIRMA);
    }//GEN-LAST:event_rinnovoCertificatoButtonActionPerformed

    private void rinnovoCertificatoCrittografiaButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rinnovoCertificatoCrittografiaButtonActionPerformed
        this.gestioneRinnovo(Utility.Utility.CRITTOGRAFIA, Integer.parseInt(keyBits1.getSelectedItem().toString()), Utility.Utility.NOME_FILE_CHIAVE_FIRMA);
    }//GEN-LAST:event_rinnovoCertificatoCrittografiaButtonActionPerformed

    private void firmaPdfButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO NON USATO
    }//GEN-LAST:event_jButton3ActionPerformed

   
    private void controllaFirmaPdfButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_controllaFirmaPdfButtonActionPerformed
        // TODO add your handling code here:
        File file;
        File certificato;
        
        JFileChooser jFileChooser1 = new javax.swing.JFileChooser();
        
        int returnVal = jFileChooser1.showOpenDialog(jFrame1);
        jFileChooser1.setDialogTitle("Scegli il pdf");
        
        if(returnVal == jFileChooser1.APPROVE_OPTION){
            try {
                file = jFileChooser1.getSelectedFile();
                
                
                
                certificato = new File("cert/my.cert");
                
               if(client.verificaPdfFirmato(file, certificato)==0){
                   statusLabel.setText("Verifica del file pdf riuscita");
               }else{
                    statusLabel.setText("Errore nella verifica del pdf");
               }
               
            } catch (XmlRpcException ex) {
                statusLabel.setText("Errore di comunicazione con la CA!");
            } catch (FileNotFoundException ex) {
                statusLabel.setText("File non trovato!");
            } catch (IOException ex) {
                statusLabel.setText("Errore nella lettura/scrittura di un file!");
            }
        
        
        
        }
        
    }//GEN-LAST:event_controllaFirmaPdfButtonActionPerformed

    private void firmaPdfActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_firmaPdfActionPerformed
        // TODO add your handling code here:
        File file;
        
        JFileChooser jFileChooser1 = new javax.swing.JFileChooser();
        
        int returnVal = jFileChooser1.showOpenDialog(jFrame1);
        
        if(returnVal == jFileChooser1.APPROVE_OPTION){
            try {
                file = jFileChooser1.getSelectedFile();
                
                if(client.firmaPdf(file)==0){
                    this.statusLabel.setText("File firmato");
                }else{
                    this.statusLabel.setText("Errore nella firma del file");
                }
            } catch (GeneralSecurityException ex) {
                this.statusLabel.setText("Errore con l'applicazione della firma!");
            } catch (IOException ex) {
                this.statusLabel.setText("Errore di lettura/scrittura file!");
            } catch (DocumentException ex) {
                this.statusLabel.setText("Il file non è un pdf valido!");
            }
        }
    }//GEN-LAST:event_firmaPdfActionPerformed

    private void decrittaPdfButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_decrittaPdfButtonActionPerformed
        // TODO add your handling code here:
        File file;
        
        JFileChooser jFileChooser1 = new javax.swing.JFileChooser();
        
        int returnVal = jFileChooser1.showOpenDialog(jFrame1);
        jFileChooser1.setDialogTitle("Scegli il pdf");
        
        if(returnVal == jFileChooser1.APPROVE_OPTION){
            try {
                file = jFileChooser1.getSelectedFile();
                       
                if(client.decrittaPdf(file)==0){
                    this.statusLabel.setText("File decrittato");
                }else{
                    this.statusLabel.setText("Errore nella decrittazione");
                }
         
            } catch (XmlRpcException ex) {
                statusLabel.setText("Errore di comunicazione con la CA!");
            } catch (GeneralSecurityException ex) {
                statusLabel.setText("Errore nella decrittazione!");
            } catch (DocumentException ex) {
                statusLabel.setText("Il file non è un pdf valido!");
            }
        
        
        }
    }//GEN-LAST:event_decrittaPdfButtonActionPerformed

    private void controllaValiditaButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_controllaValiditaButtonActionPerformed
        // TODO add your handling code here:
        
         File file;
        
        JFileChooser jFileChooser1 = new javax.swing.JFileChooser();
        
        int returnVal = jFileChooser1.showOpenDialog(jFrame1);
        
        if(returnVal == jFileChooser1.APPROVE_OPTION){
            try {
                
                file = jFileChooser1.getSelectedFile();
                
                try {
                    if(client.controllaValidita(file)==0){
                        this.statusLabel.setText("Certificato valido");
                    }else{
                        this.statusLabel.setText("Certificato revocato");
                    }
                } catch (OCSPException ex) {
                    Logger.getLogger(ClientGui.class.getName()).log(Level.SEVERE, null, ex);
                } catch (XmlRpcException ex) {
                        this.statusLabel.setText("Errore di comunicazione con la CA!");

                }
                
            } catch (CRLException ex) {
                        this.statusLabel.setText("Errore con la CRL!");

            } catch (CertificateException ex) {
                        this.statusLabel.setText("Errore nella gestione dei certificati!");

            } catch (IOException ex) {
                this.statusLabel.setText("Errore di lettura/scrittura file!");
            }
        }
    }//GEN-LAST:event_controllaValiditaButtonActionPerformed

    
    private void crittaPdfButtonActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        File file;
        
        JFileChooser jFileChooser1 = new javax.swing.JFileChooser();
        
        int returnVal = jFileChooser1.showOpenDialog(jFrame1);
        
        if(returnVal == jFileChooser1.APPROVE_OPTION){
            try {
                file = jFileChooser1.getSelectedFile();
               
                if(client.crittaPdf(file)==0){
                    this.statusLabel.setText("File crittato");
                }else{
                    this.statusLabel.setText("Errore nella crittografia");
                }
            } catch (IOException ex) {
                statusLabel.setText("File non trovato!");
            } catch (DocumentException ex) {
                statusLabel.setText("Il file non è un pdf valido!");
            } catch (CertificateException ex) {
                statusLabel.setText("Errore nel certificato!");
            }
        }
    } 
    
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ClientGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ClientGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ClientGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ClientGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new ClientGui(new Client(Utility.Utility.URL_SERVER)).setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField cognome;
    private javax.swing.JButton controllaFirmaPdfButton;
    private javax.swing.JButton controllaValiditaButton;
    private javax.swing.JTextField country;
    private javax.swing.JButton crittaPdfButton;
    private javax.swing.JButton decrittaPdfButton;
    private javax.swing.JTextField email;
    private javax.swing.JButton firmaPdf;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JFrame jFrame1;
    private javax.swing.JFrame jFrame2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JComboBox keyBits1;
    private javax.swing.JTextField nome;
    private javax.swing.JTextField organization;
    private javax.swing.JButton ottieniCertificatoButton;
    private javax.swing.JButton ottieniCrittografiaButton;
    private javax.swing.JPasswordField password;
    private javax.swing.JPasswordField passwordEsistente;
    private javax.swing.JButton revocaCertificatoBUtton;
    private javax.swing.JButton revocaCrittografiaButton;
    private javax.swing.JButton richiediCertificatoButton;
    private javax.swing.JButton richiediCrittografiaButton;
    private javax.swing.JButton rinnovoCertificatoButton;
    private javax.swing.JButton rinnovoCertificatoCrittografiaButton;
    private javax.swing.JLabel statusLabel;
    private javax.swing.JTextField unit;
    // End of variables declaration//GEN-END:variables
}
